#pragma once
#include <mutex>
#include <atomic>
#include <unordered_map>
#include <iostream>

class Count{
public:
	struct MemStruct{
		enum DelWay{
			None,
			GC,
			Auto,
		}delWay=None;
		bool isStack=false;
		bool isGloab=false;
		bool isDel=false;
		int id=-1;
		MemStruct(int id,bool isStack,bool isGloab):isStack(isStack),isGloab(isGloab),id(id){};
		MemStruct(){};
	};
private:
	std::atomic<int> gid;
	std::mutex mutDict;
	std::unordered_map<void*,MemStruct> dict;
public:
	Count():gid(0){};
	void insertDict(void* ptr,bool isStack,bool isGloab,int id=0){
		mutDict.lock();
		dict.insert({ptr,MemStruct((id<0?id:gid++),isStack,isGloab)});
		mutDict.unlock();
	}
	void delDict(void* ptr,MemStruct::DelWay delway){
		mutDict.lock();
		if (dict.find(ptr)!=dict.end()) {
			dict[ptr].isDel=true;
			dict[ptr].delWay=delway;
		}
		mutDict.unlock();
	}
	inline const std::unordered_map<void*, MemStruct> getCount()const{return dict;}
}count;
